﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint.WebControls;

namespace IronSharePoint.Web.WebControls
{
    public class IronFieldEditor : IronUserControl, IFieldEditor
    {
        #region IFieldEditor Members

        public bool DisplayAsNewSection
        {
            get 
            {
                EnsureScriptEngine();

                if (engine.Scope.ContainsVariable("DisplayAsNewSection"))
                {
                    object method = engine.Scope.GetVariable("DisplayAsNewSection");
                    return (bool)engine.Operations.Call(method);
                }

                return false;
            }
        }

        public void InitializeWithField(Microsoft.SharePoint.SPField field)
        {
            EnsureScriptEngine();

            if (engine.Scope.ContainsVariable("InitializeWithField"))
            {
                object method = engine.Scope.GetVariable("InitializeWithField");
                engine.Operations.Call(method,field);
            }
        }

        public void OnSaveChange(Microsoft.SharePoint.SPField field, bool isNewField)
        {

            EnsureScriptEngine();

            if (engine.Scope.ContainsVariable("OnSaveChange"))
            {
                object method = engine.Scope.GetVariable("OnSaveChange");
                engine.Operations.Call(method, field, isNewField);
            }
        }

        #endregion
    }
}
